package com.wise.service.cms.content.setting;

import com.wise.entities.content.Setting;
import com.wise.framework.daomodel.DaoOne4Update;
import com.wise.framework.daomodel.DaoSave;
import com.wise.framework.validation.Precondition;
import com.wise.summer.v1.cms.content.setting.DeleteSetting;
import com.wise.summer.v1.cms.content.settings.ListSettings;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;
import org.summerframework.model.SummerService;
import org.summerframework.model.SummerServiceBean;

import java.util.List;

import static com.wise.model.content.ContentErrMsgs.Err_000100010001;


/**
 * @author futao
 * @date 2019/06/17
 */
@Service
@SummerService
public class DeleteSettingService implements SummerServiceBean<DeleteSetting> {
    @Override
    public void sum(DeleteSetting model) {
        Precondition.checkState(StringUtils.isNotBlank(model.getName()), this.getClass(), Err_000100010001);
        List<Setting> infoList = ListSettings.s(model.getName());
        if (infoList.size() > 0) {
            Setting s = DaoOne4Update.s(Setting.class, infoList.get(0).getId(), null);
            s.setInfo(null);
            DaoSave.s(s);
            model.setSummerResult(true);
        }
    }
}
